// Copyright 2012 dmitry.a.novikov@gmail.com
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "consistenz.h"
#include "core.h"
#include "dictionary.h"
#include "objectimpl.h"
#include "dictionaryimpl.h"
#include "stream.h"
#include "storage.h"

namespace CnsZ {

#define CNSZ_CLASS_TABLE() \
    CNSZ_CLASS(          Object,        0     ) \
    CNSZ_CLASS(           Class,   Object     ) \
    CNSZ_CLASS(          Handle,   Object     ) \
    CNSZ_CLASS(      Dictionary,   Object     ) \

  DEFINE_CNSZ_CLASS(Class, Object, NULL_FACTORY);

  String System::findFile(const String& ) {
    return String();
  }

  P<Stream> System::file(const String& pathName, int options) {
    return P<Stream>();
  }

  class Module : public Object {
  public:
  };

  P<Module> System::loadModule(const String& name) {
    return P<Module>();
  }

  class CoreImpl : public Core {
  public:
    P<Dictionary> classes() const {
      static ImplNoRefCount<DictionaryImpl<> > classesDict;
      return &classesDict;
    }

  };

  Int64 Settings::getInteger(IntegerSettingId id) {
    return 0;
  }

  Real Settings::getReal(RealSettingId id) {
    return 0.;
  }

  String Settings::getString(StringSettingId id) {
    switch(id) {
    case AppName:
      return String(L"Consistenz Application");
    case AppStorageFileName:
      return String(L"Consistenz Application");
    }
    return String();
  }

  System* g_system;
  Settings* g_settings;

  P<Object> Settings::getObject(ObjectSettingId id) {
    switch(id) {
    case AppStorage:
      {
        String fn = g_system->findFile(getString(AppStorageFileName));
//        return Storage::New(g_system->file(fn, g_system->CreateIfNotFound)).get();
      }
    }
    return P<Object>();
  }

  P<Core> Core::initialize(System& system, Settings& settings) {
    g_system = &system;
    g_settings = &settings;
    OBJECTIMPL_FACTORY(CoreImpl).get();
  }

}//namespace CnsZ
